package com.examiner.result;

import lombok.*;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> {

    private Integer code; // 响应码
    private String message; // 响应信息
    private Boolean flag; // 执行结果
    private T data; // 响应数据

    public Result(ResultCode resultCode, Boolean flag, T data) {
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.flag = flag;
        this.data = data;
    }


    // <T> 泛型定义
    // Result<T> 泛型的引用
    public static <T> Result<T> SUCCESS(T data) {
        return new Result<>(ResultCode.SUCCESS, true, data);
    }

    public static <T> Result<T> FAIL(T data) {
        return new Result<>(ResultCode.FAIL, false, data);
    }

    public static <T> Result<T> RESULT(Integer code, String message, Boolean flag, T data) {
        return new Result<>(code, message, flag, data);
    }

}
